// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.network.packets.hit;

import java.nio.ByteBuffer;
import zombie.characters.IsoLivingCharacter;
import zombie.characters.IsoPlayer;
import zombie.core.network.ByteBufferWriter;
import zombie.core.raknet.UdpConnection;
import zombie.inventory.types.HandWeapon;
import zombie.network.packets.INetworkPacket;

public abstract class PlayerHitPacket extends HitCharacterPacket implements INetworkPacket {
    protected final Player wielder = new Player();
    protected final Weapon weapon = new Weapon();

    public PlayerHitPacket(HitCharacterPacket.HitType hitType) {
        super(hitType);
    }

    public void set(IsoPlayer _wielder, HandWeapon _weapon, boolean isCriticalHit) {
        this.wielder.set(_wielder, isCriticalHit);
        this.weapon.set(_weapon);
    }

    @Override
    public void parse(ByteBuffer b, UdpConnection connection) {
        this.wielder.parse(b, connection);
        this.wielder.parsePlayer(connection);
        this.weapon.parse(b, (IsoLivingCharacter)this.wielder.getCharacter());
    }

    @Override
    public void write(ByteBufferWriter b) {
        super.write(b);
        this.wielder.write(b);
        this.weapon.write(b);
    }

    @Override
    public boolean isRelevant(UdpConnection connection) {
        return this.wielder.isRelevant(connection);
    }

    @Override
    public boolean isConsistent() {
        return super.isConsistent() && this.weapon.isConsistent() && this.wielder.isConsistent();
    }

    @Override
    public String getDescription() {
        return super.getDescription() + "\n\tWielder " + this.wielder.getDescription() + "\n\tWeapon " + this.weapon.getDescription();
    }

    @Override
    protected void preProcess() {
        this.wielder.process();
    }

    @Override
    protected void postProcess() {
        this.wielder.process();
    }

    @Override
    protected void attack() {
        this.wielder.attack(this.weapon.getWeapon(), false);
    }

    @Override
    protected void react() {
    }
}
